// drag objects with drag="true" attribute
var startDrag = function(e, onDrag, beforeDrag){
	var fobj = browser.isIE ? event.srcElement : e.target;
	if(fobj.tagName.toLowerCase() == 'div'){
		while(fobj.tagName != "body" && fobj.getAttribute("drag") != "true") fobj = fobj.parentNode;
		if(fobj.getAttribute("drag") == "true"){
			var tx = parseInt(fobj.style.left + 0, 10);
			var ty = parseInt(fobj.style.top + 0, 10);
			var x = browser.isIE ? event.clientX : e.clientX;
			var y = browser.isIE ? event.clientY : e.clientY;
			onTop(fobj);
			document.onmouseup = function(){ document.onmousemove = null; document.onmouseup = null; };
			document.onmousemove = function(e){
				if(beforeDrag) beforeDrag(fobj);
				fobj.style.left = browser.isIE ? tx + event.clientX - x : tx + e.clientX - x;
				fobj.style.top = browser.isIE ? ty + event.clientY - y : ty + e.clientY - y;
				if(onDrag) onDrag(fobj);
			};
		}
	}
};

// make node lastChild (in html visual on top :-)
var onTop = function(tg){
	var Parent = tg.parentNode;
	if(Parent.lastChild != tg) Parent.appendChild( Parent.removeChild(tg) );
};
